/*
 * WeekHeader.java
 *
 * Created on Oct 19, 2011, 8:07:25 AM
 */
package carassius.GUI.Calendar;

import carassius.BLL.GregorianCalendarWithEvents;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.GregorianCalendar;

/**
 *
 * @author siebz0r
 */
public class WeekHeaderPanel
		extends javax.swing.JPanel
		implements PropertyChangeListener
{
	private GregorianCalendarWithEvents _calendar;

	/** Creates new form WeekHeader */
	public WeekHeaderPanel()
	{
		this(new GregorianCalendarWithEvents());
	}

	public WeekHeaderPanel(GregorianCalendarWithEvents calendar)
	{
		_calendar = calendar;
		initComponents();
		setLabels();
		_calendar.addPropertyChangeListener("year", this);
		_calendar.addPropertyChangeListener("month", this);
	}

	public WeekHeaderPanel(int month, int year)
	{
		this(new GregorianCalendarWithEvents(year, month, new GregorianCalendar().get(GregorianCalendar.DATE)));
	}

	public int getMonth()
	{
		return _calendar.get(GregorianCalendar.MONTH);
	}

	public void setMonth(int month)
	{
		_calendar.set(GregorianCalendar.MONTH, month);
	}

	public int getYear()
	{
		return _calendar.get(GregorianCalendar.YEAR);
	}

	public void setYear(int year)
	{
		_calendar.set(GregorianCalendar.YEAR, year);
	}

	private void setLabels()
	{
		GregorianCalendar cal = (GregorianCalendar) _calendar.clone();
		cal.set(GregorianCalendar.DATE, 1);

		uxWeekLabel1.setText(Integer.toString(cal.get(GregorianCalendar.WEEK_OF_YEAR)));
		cal.add(GregorianCalendar.WEEK_OF_YEAR, 1);

		uxWeekLabel2.setText(Integer.toString(cal.get(GregorianCalendar.WEEK_OF_YEAR)));
		cal.add(GregorianCalendar.WEEK_OF_YEAR, 1);

		uxWeekLabel3.setText(Integer.toString(cal.get(GregorianCalendar.WEEK_OF_YEAR)));
		cal.add(GregorianCalendar.WEEK_OF_YEAR, 1);

		uxWeekLabel4.setText(Integer.toString(cal.get(GregorianCalendar.WEEK_OF_YEAR)));
		cal.add(GregorianCalendar.WEEK_OF_YEAR, 1);

		uxWeekLabel5.setText(Integer.toString(cal.get(GregorianCalendar.WEEK_OF_YEAR)));
		cal.add(GregorianCalendar.WEEK_OF_YEAR, 1);

		uxWeekLabel6.setText(Integer.toString(cal.get(GregorianCalendar.WEEK_OF_YEAR)));
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        uxWeekLabel1 = new javax.swing.JLabel();
        uxWeekLabel2 = new javax.swing.JLabel();
        uxWeekLabel3 = new javax.swing.JLabel();
        uxWeekLabel4 = new javax.swing.JLabel();
        uxWeekLabel5 = new javax.swing.JLabel();
        uxWeekLabel6 = new javax.swing.JLabel();

        setMaximumSize(new java.awt.Dimension(20, 162));
        setMinimumSize(new java.awt.Dimension(20, 162));
        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(20, 162));
        setLayout(new java.awt.GridLayout(6, 0));

        uxWeekLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(carassius.CarassiusApp.class).getContext().getResourceMap(WeekHeaderPanel.class);
        uxWeekLabel1.setText(resourceMap.getString("uxWeekLabel1.text")); // NOI18N
        uxWeekLabel1.setName("uxWeekLabel1"); // NOI18N
        add(uxWeekLabel1);

        uxWeekLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        uxWeekLabel2.setText(resourceMap.getString("uxWeekLabel2.text")); // NOI18N
        uxWeekLabel2.setName("uxWeekLabel2"); // NOI18N
        add(uxWeekLabel2);

        uxWeekLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        uxWeekLabel3.setText(resourceMap.getString("uxWeekLabel3.text")); // NOI18N
        uxWeekLabel3.setName("uxWeekLabel3"); // NOI18N
        add(uxWeekLabel3);

        uxWeekLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        uxWeekLabel4.setText(resourceMap.getString("uxWeekLabel4.text")); // NOI18N
        uxWeekLabel4.setName("uxWeekLabel4"); // NOI18N
        add(uxWeekLabel4);

        uxWeekLabel5.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        uxWeekLabel5.setText(resourceMap.getString("uxWeekLabel5.text")); // NOI18N
        uxWeekLabel5.setName("uxWeekLabel5"); // NOI18N
        add(uxWeekLabel5);

        uxWeekLabel6.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        uxWeekLabel6.setText(resourceMap.getString("uxWeekLabel6.text")); // NOI18N
        uxWeekLabel6.setName("uxWeekLabel6"); // NOI18N
        add(uxWeekLabel6);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel uxWeekLabel1;
    private javax.swing.JLabel uxWeekLabel2;
    private javax.swing.JLabel uxWeekLabel3;
    private javax.swing.JLabel uxWeekLabel4;
    private javax.swing.JLabel uxWeekLabel5;
    private javax.swing.JLabel uxWeekLabel6;
    // End of variables declaration//GEN-END:variables

	@Override
	public void propertyChange(PropertyChangeEvent evt)
	{
		if ("month".equals(evt.getPropertyName())
				|| "year".equals(evt.getPropertyName()))
		{
			setLabels();
		}
	}
}
